﻿using DAL;
using DAL.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Web.ViewModel;

namespace Web.Controllers
{
    public class HotelController : Controller
    {
        private readonly ICouchRepository repo;
        private const int take = 20;
        public HotelController(ICouchRepository repo)
        {
            this.repo = repo;
        }
        public ActionResult Index(int? page)
        {
            var pageNumber = page ?? 1;
            var result = repo.GetAllRecord(take, pageNumber * take);
            var viewModel = new HotelList(result, pageNumber, take);
      
            return View("Index", viewModel);
        }

        public ActionResult Details(string token)
        {
            var result = repo.GetRecordByToken(token);
            var vm = AutoMapper.Mapper.DynamicMap<DAL.Model.Local.HotelShortModel, HotelDetails>(result.Hotel);
            return PartialView("_HotelDetailsPartial",vm);
        }
        public ActionResult GetHotelByCountry(string SearchString, int? page)
        {
            var pageNumber = page ?? 1;
            List<SunHotelsHotelEntities> list = repo.GetAllRecordByCountry(SearchString, take, pageNumber * take);
            var viewModel = list;
            return View("GetHotelByCountry", viewModel);
        }
        public ActionResult GetHotelByCity(string SearchString, int? page)
        {
            var pageNumber = page ?? 1;
            List<SunHotelsHotelEntities> list = repo.GetAllRecordByCity(SearchString, take, pageNumber * take);
            var viewModel = list;
            return View("GetHotelByCity", viewModel);
        }
        public JsonResult GetCountry(string query)
        {
           // if (!String.IsNullOrEmpty(query))
            {
             //   if (query.Length >= 2)
                {
                    var country = new[]
                    { 
                        new { id =  "aa", text = "aa" },
                        new { id =  "bb", text ="bb" },
                        new { id = "c.Key", text = "c." },
                        new { id = "c.Ke22y", text = "111" }
                    }.ToList();

                  

                    return Json(country, JsonRequestBehavior.AllowGet);
                }
            }
            return Json(null, JsonRequestBehavior.AllowGet);
        }
    }
}
